<?php
GLOBAL $CFG;
require_once('../../../config.php');
$img_path = $CFG->wwwroot.'/local/blackboxsurvey/image/';
require_once($CFG->libdir . '/formslib.php');
require_once($CFG->dirroot . '/local/blackboxsurvey/lib.php');
require_once($CFG->dirroot . "/local/blackboxsurvey/forms.php");
//class
require_once($CFG->dirroot . "/local/blackboxsurvey/class/questions.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/question_type.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/survey.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/user.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/questionaire.php");
require_once($CFG->dirroot . "/local/blackboxsurvey/class/matching.php");
//path
$path_image = $CFG->wwwroot .'/local/blackboxsurvey/image/';

$show = optional_param('show',null, PARAM_TEXT);
/****************************************************************************************************************************************************************
 * 								                                         USE FOR SURVEY MANAGEMENT (ADMIN)
 ****************************************************************************************************************************************************************/
//hien b?ng add question trong create survey
if($show == 'add_question_create_survey')
{
    $id = optional_param('id',null, PARAM_TEXT);
    $temp = new b_survey();
    $str = '<div id="Filter" >'.get_string('search_question', 'local_blackboxsurvey').': <input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';
    $str = $str.$temp->load_question_add_to_survey('', '',$id);
    $array = array();
    $array['str'] = $str;
    $array['survey_id'] = $id;
    /* Viet doan code cua ban o day */
    $mform = new form_add_survey_question(null, $array);
    $mform->display();
    echo "<script type='text/javascript'>filter();</script>"; 
}
//hien colorbox add matchmaker, dung trong create &edit survey
elseif($show == 'add_matcher_create_survey')
{
    $id = optional_param('id',null, PARAM_TEXT);
    $c_user = new b_user();
    $str = '<div id="Filter" > Seach <input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';
    $str = $str.$c_user->load_all_user();
    $array = array();
    $array['str'] = $str;
    $array['survey_id'] = $id;
    /* Viet doan code cua ban o day */
    $mform = new form_add_survey_question(null, $array);
    $mform->display();
    echo "<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach cau hoi de add vao survey, chi dung cho edit
elseif($show == 'add_question_edit_survey')
{
    $temp = new b_survey();
    
    $id = optional_param('id',null, PARAM_TEXT);
    //$temp_ques = optional_param('array_ques',null, PARAM_TEXT);
    $temp_ques = $temp->load_survey_question_cache($id);
    $ques_array = explode('||',$temp_ques);

    $str = '<div id="Filter" >'.get_string('search_question', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';
    $str = $str.$temp->load_question_add_to_survey_edit_only('', '',$ques_array);
    $array = array();
    $array['str'] = $str;
    $array['array_ques'] = $temp_ques;
    $array['survey_id'] = $id;
    /* Viet doan code cua ban o day */
    $mform = new form_add_survey_question_edit_only(null, $array);
    $mform->display();
    echo "<script type='text/javascript'>filter();</script>"; 
}
/****************************************************************************************************************************************************************
 * 								                                         USE FOR QUESTIONAIRE MANAGEMENT (LECTURER)
 ****************************************************************************************************************************************************************/
//hien danh sach learning outcome de chon, dung cho input
elseif($show == 'load_inlo_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $qn_id = optional_param('qn_id',null, PARAM_TEXT);
    $id_program = optional_param('id_program',null, PARAM_TEXT);

    $str = '<div id="Filter" >'.get_string('searchsubject', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';

    $str = $str.$c_qn->load_inlo_add_to_questionaire($qn_id,$id_program);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach subject de add cho 1 input
elseif($show == 'load_input_sub_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $id_input = optional_param('id_input',null, PARAM_TEXT);
    $id_program = optional_param('id_program',null, PARAM_TEXT);
    $id_qn= optional_param('id_qn',null, PARAM_TEXT);
    $id_subject = optional_param('id_subject',null, PARAM_TEXT);

    $str = '<div id="Filter" >'.get_string('searchsubject', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';

    $str = $str.$c_qn->load_input_sub_do_questionaire($id_input,$id_program,$id_qn,$id_subject);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach learning outcome index de add cho 1 new input
elseif($show == 'load_inlo_index_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $id_input = optional_param('id_input',null, PARAM_TEXT);
    $id_program = optional_param('id_program',null, PARAM_TEXT);

    $str = '<div id="Filter" >'.get_string('searchsubject', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';

    $str = $str.$c_qn->show_inlo_index_questionaire($id_input,$id_program);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach learning outcome de chon, dung cho output torng do & edit questionaire
elseif($show == 'load_outlo_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $qn_id = optional_param('qn_id',null, PARAM_TEXT);
    $id_program = optional_param('id_program',null, PARAM_TEXT);

    $str = '<div id="Filter" >'.get_string('searchsubject', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';

    $str = $str.$c_qn->load_outlo_add_to_questionaire($qn_id,$id_program);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach subject de add cho 1 output
elseif($show == 'load_output_sub_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $id_output = optional_param('id_output',null, PARAM_TEXT);
    $id_program = optional_param('id_program',null, PARAM_TEXT);
    $id_qn= optional_param('id_qn',null, PARAM_TEXT);
    $id_subject = optional_param('id_subject',null, PARAM_TEXT);

    $str = '<div id="Filter" >'.get_string('searchsubject', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';

    $str = $str.$c_qn->load_output_sub_do_questionaire($id_output,$id_program, $id_qn, $id_subject);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach learning outcome index de add cho 1 new output
elseif($show == 'load_outlo_index_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $id_output = optional_param('id_output',null, PARAM_TEXT);
    $id_program = optional_param('id_program',null, PARAM_TEXT);

    $str = '<div id="Filter" >'.get_string('searchsubject', 'local_blackboxsurvey').'<input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';

    $str = $str.$c_qn->show_outlo_index_questionaire($id_output,$id_program);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach learning outcome de chon, dung cho output torng do & edit questionaire
elseif($show == 'load_request_do_questionaire')
{
    $c_qn = new b_questionaire();
    
    $qn_id = optional_param('qn_id',null, PARAM_TEXT);

    $str = '<div id="Filter" >Search: <input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';
    $str = $str.$c_qn->load_request_add_to_questionaire($qn_id);
    echo $str."<script type='text/javascript'>filter();</script>"; 
}
//hien danh sach input de matching cho ouput
elseif($show == 'show_matching_outin')
{
    $c_mat = new b_matching();
    
    $id_bbsurvey = optional_param('id_bbsurvey',null, PARAM_TEXT);
    $id_subject = optional_param('id_subject',null, PARAM_TEXT);
    $id_output = optional_param('id_output',null, PARAM_TEXT);
    
    global $DB;
    $op = $DB->get_record('b_output', array('id'=>$id_output));
    $str .= '<h2 style="color:red">Matching Output : '.$op->content.'</h2>';
    
    $str .= '<div id="Filter" > Search <input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';
    $str = $str.$c_mat->show_matching_outin($id_bbsurvey, $id_subject, $id_output);
    echo $str."<script type='text/javascript'>filter();</script>";
}
//hien danh sach input de add
elseif($show == 'load_input_course_teach'){
    $c_mat = new b_matching();
    
    $id_input = optional_param('id',null,PARAM_TEXT);
    
    $str .= '<div id="Filter" > Search <input type=text id="FilterTextBox" name="FilterTextBox" size="40"/><img onclick="clear_filter();" style="cursor:pointer;" src="'.$path_image.'clear.jpg"/></div><br>';
    $str = $str.$c_mat->load_input_course_teach($id_input);
    
    echo $str."<script type='text/javascript'>filter();show_hide_teach_course_cb();</script>";
}
//hien danh sach input de add
elseif($show == 'show_logs'){
    $c_mat = new b_matching();
    
    $id_bbsurvey = optional_param('id_bbsurvey',null,PARAM_TEXT);
    
    $str = $c_mat->show_logs($id_bbsurvey);
    
    echo $str;
}
/*------Ket thuc doan code cua ban-------*/
